package io.kiki.stack.netty.config;

import io.kiki.stack.netty.Client;

/**
 * Define the key for a certain config item using system property,
 * and provide the default value for that config item.
 *
 * @author tsui
 * @version $Id: Configs.java, v 0.1 2017-08-03 19:21 tsui Exp $
 */
public class Configs {
    // ~~~ configs and default values for bootstrap

    /**
     * TCP_NODELAY option
     */
    public static final String TCP_NODELAY = "tcp.nodelay";
    public static final String TCP_NODELAY_DEFAULT = "true";

    /**
     * TCP SO_REUSEADDR option
     */
    public static final String TCP_SO_REUSEADDR = "tcp.so.reuseaddr";
    public static final String TCP_SO_REUSEADDR_DEFAULT = "true";

    /**
     * TCP SO_BACKLOG option
     */
    public static final String TCP_SO_BACKLOG = "tcp.so.backlog";
    public static final String TCP_SO_BACKLOG_DEFAULT = "1024";

    /**
     * TCP SO_KEEPALIVE option
     */
    public static final String TCP_SO_KEEPALIVE = "tcp.so.keepalive";
    public static final String TCP_SO_KEEPALIVE_DEFAULT = "true";

    /**
     * TCP SO_SNDBUF option
     */
    public static final String TCP_SO_SNDBUF = "tcp.so.sndbuf";
    /**
     * TCP SO_RCVBUF option
     */
    public static final String TCP_SO_RCVBUF = "tcp.so.rcvbuf";

    /**
     * Netty ioRatio option
     */
    public static final String NETTY_IO_RATIO = "netty.io.ratio";
    public static final String NETTY_IO_RATIO_DEFAULT = "70";

    /**
     * Netty buffer allocator, enabled as default
     */
    public static final String NETTY_BUFFER_POOLED = "netty.buffer.pooled";
    public static final String NETTY_BUFFER_POOLED_DEFAULT = "true";

    /**
     * Netty buffer high watermark
     */
    public static final String NETTY_BUFFER_HIGH_WATERMARK = "netty.buffer.high.watermark";
    public static final String NETTY_BUFFER_HIGH_WATERMARK_DEFAULT = Integer.toString(64 * 1024);

    /**
     * Netty buffer low watermark
     */
    public static final String NETTY_BUFFER_LOW_WATERMARK = "netty.buffer.low.watermark";
    public static final String NETTY_BUFFER_LOW_WATERMARK_DEFAULT = Integer.toString(32 * 1024);

    /**
     * Netty epoll switch
     */
    public static final String NETTY_EPOLL_SWITCH = "netty.epoll.switch";
    public static final String NETTY_EPOLL_SWITCH_DEFAULT = "true";

    /**
     * Netty epoll level trigger enabled
     */
    public static final String NETTY_EPOLL_LT = "netty.epoll.lt";
    public static final String NETTY_EPOLL_LT_DEFAULT = "true";

    // ~~~ configs and default values for idle

    /**
     * TCP idle switch
     */
    public static final String TCP_IDLE_SWITCH = "tcp.heartbeat.switch";
    public static final String TCP_IDLE_SWITCH_DEFAULT = "true";

    /**
     * TCP idle interval for client
     */
    public static final String TCP_IDLE = "tcp.heartbeat.interval";
    public static final String TCP_IDLE_DEFAULT = "15000";

    /**
     * TCP idle triggered max times if no response
     */
    public static final String TCP_IDLE_MAXTIMES = "tcp.heartbeat.maxtimes";
    public static final String TCP_IDLE_MAXTIMES_DEFAULT = "3";

    /**
     * TCP idle interval for server
     */
    public static final String TCP_SERVER_IDLE = "tcp.server.idle.interval";
    public static final String TCP_SERVER_IDLE_DEFAULT = "90000";

    // ~~~ configs and default values for channel manager

    /**
     * Thread pool min size for the channel manager executor
     */
    public static final String CONN_CREATE_TP_MIN_SIZE = "conn.create.tp.min";
    public static final String CONN_CREATE_TP_MIN_SIZE_DEFAULT = "3";

    /**
     * Thread pool max size for the channel manager executor
     */
    public static final String CONN_CREATE_TP_MAX_SIZE = "conn.create.tp.max";
    public static final String CONN_CREATE_TP_MAX_SIZE_DEFAULT = "8";

    /**
     * Thread pool queue size for the channel manager executor
     */
    public static final String CONN_CREATE_TP_QUEUE_SIZE = "conn.create.tp.queue";
    public static final String CONN_CREATE_TP_QUEUE_SIZE_DEFAULT = "50";

    /**
     * Thread pool keep alive time for the channel manager executor
     */
    public static final String CONN_CREATE_TP_KEEPALIVE_TIME = "conn.create.tp.keepalive";
    public static final String CONN_CREATE_TP_KEEPALIVE_TIME_DEFAULT = "60";

    /**
     * Default connect timeout value, time unit: ms
     */
    public static final int DEFAULT_CONNECT_TIMEOUT = 1000;

    /**
     * default channel number per url
     */
    public static final int DEFAULT_CONN_NUM_PER_URL = 1;

    /**
     * max channel number of each url
     */
    public static final int MAX_CONN_NUM_PER_URL = 100 * 10000;

    // ~~~ configs for processor manager

    /**
     * Thread pool min size for the default executor.
     */
    public static final String TP_MIN_SIZE = "tp.min";
    public static final String TP_MIN_SIZE_DEFAULT = "20";

    /**
     * Thread pool max size for the default executor.
     */
    public static final String TP_MAX_SIZE = "tp.max";
    public static final String TP_MAX_SIZE_DEFAULT = "400";

    /**
     * Thread pool queue size for the default executor.
     */
    public static final String TP_QUEUE_SIZE = "tp.queue";
    public static final String TP_QUEUE_SIZE_DEFAULT = "600";

    /**
     * Thread pool keep alive time for the default executor
     */
    public static final String TP_KEEPALIVE_TIME = "tp.keepalive";
    public static final String TP_KEEPALIVE_TIME_DEFAULT = "60";

    // ~~~ configs and default values for reconnect manager

    /**
     * Reconnect switch
     */
    public static final String CONN_RECONNECT_SWITCH = "conn.reconnect.switch";
    public static final String CONN_RECONNECT_SWITCH_DEFAULT = "false";

    // ~~~ configs and default values for channel monitor

    /**
     * channel monitor switch
     * <p>
     * If switch on channel monitor, it may cause {@link Client#oneway} to fail.
     * Please try to use other types of RPC methods
     * </p>
     */
    public static final String CONN_MONITOR_SWITCH = "conn.monitor.switch";
    public static final String CONN_MONITOR_SWITCH_DEFAULT = "false";

    /**
     * Initial delay to execute schedule task for channel monitor
     */
    public static final String CONN_MONITOR_INITIAL_DELAY = "conn.monitor.initial.delay";
    public static final String CONN_MONITOR_INITIAL_DELAY_DEFAULT = "10000";

    /**
     * Period of schedule task for channel monitor
     */
    public static final String CONN_MONITOR_PERIOD = "conn.monitor.period";
    public static final String CONN_MONITOR_PERIOD_DEFAULT = "180000";

    /**
     * channel threshold
     */
    public static final String CONN_THRESHOLD = "conn.threshold";
    public static final String CONN_THRESHOLD_DEFAULT = "3";

    /**
     * Retry detect period for ScheduledDisconnectStrategy
     */
    @Deprecated
    public static final String RETRY_DETECT_PERIOD = "retry.delete.period";
    public static final String RETRY_DETECT_PERIOD_DEFAULT = "5000";

    /**
     * channel status
     */
    public static final String CONN_SERVICE_STATUS = "conn.service.status";
    public static final String CONN_SERVICE_STATUS_OFF = "off";
    public static final String CONN_SERVICE_STATUS_ON = "on";

    // ~~~ configs and default values for serializer

    public static final String DEFAULT_CHARSET = "UTF-8";
}
